package com.suray.wcs.web.system.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.suray.commin.annotation.Log;
import com.suray.commin.core.controller.BaseController;
import com.suray.commin.core.controller.ResponseData;
import com.suray.commin.core.page.TableDataInfo;
import com.suray.commin.core.utils.ExcelUtil;
import com.suray.commin.enmus.BusinessType;
import com.suray.wcs.service.system.entity.InterfaceLogDB;
import com.suray.wcs.service.system.entity.OperationLogDB;
import com.suray.wcs.service.system.service.impl.InterfaceLogServiceImpl;
import com.suray.wcs.service.wmsconnect.WmsResponses;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/interfaceLog")
@CrossOrigin(value = "*", allowCredentials = "true")
public class InterfaceLogController extends BaseController {

    @Autowired
    private InterfaceLogServiceImpl interfaceLogService;

    /**
     * 分页查询
     *
     * @param interfaceLogDB
     * @return
     */
    @PreAuthorize("@ss.hasPermi('interfaceLog:list')")
    @ApiOperation(value = "查询接口日志")
    @GetMapping(value = "/getInterfaceLog")
    @ResponseBody
    public TableDataInfo getInterfaceLog(InterfaceLogDB interfaceLogDB) {
        startPage();
        List<InterfaceLogDB> interfaceLogs = interfaceLogService.getInterfaceLogs(interfaceLogDB);
        return getDataTable(interfaceLogs);
    }

    @Log(title = "操作日志", method = "导出操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('interfaceLog:export')")
    @GetMapping("/export")
    public ResponseData export(InterfaceLogDB interfaceLogDB) {
        List<InterfaceLogDB> list = interfaceLogService.getInterfaceLogs(interfaceLogDB);
        ExcelUtil<InterfaceLogDB> util = new ExcelUtil<>(InterfaceLogDB.class);
        return util.exportExcel(list, "操作日志");
    }

    @PreAuthorize("@ss.hasPermi('interfaceLog:remove')")
    @Log(title = "操作日志", method = "删除操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{interfaceLogIds}")
    public ResponseData remove(@PathVariable Long[] interfaceLogIds) {
        return toAjax(interfaceLogService.deleteLogByIds(interfaceLogIds));
    }

    @Log(title = "操作日志", method = "清空操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('interfaceLog:remove')")
    @DeleteMapping("/clean")
    public ResponseData clean() {
        interfaceLogService.cleanLog();
        return ResponseData.success();
    }
}
